

function httpRequest($JQuery,data){
    var dataSource;
    $JQuery.ajax({
        url: getIP() + '/prodetail/proCruxNode',
        async:false,
        type: 'post',
        contentType:'application/json',
        dataType:"json",
        data:JSON.stringify(data),
        success: function (data) {
            if (data.code == "succee") {
                dataSource = data.data;
            }
        }
    });
    return dataSource;
}


function httpRequestConn($JQuery,data) {
    var dataSource;
    $JQuery.ajax({
        url: getIP() + '/prodetail/proMinorNode',
        async:false,
        type: 'post',
        contentType:'application/json',
        dataType:"json",
        data:JSON.stringify(data),
        success: function (data) {
            if (data.code == "succee") {
                dataSource = data.data;
            }
        }
    });
    return dataSource;
}

function reloadDom(dataSource,$JQuery) {
	if(dataSource != undefined){
		var ProNodePlan = dataSource.ProNodePlan,
		    ProNodeActual = dataSource.ProNodeActual,
		    conLabel = dataSource.conLabel;
	}
    
    var $domJH = $JQuery('.timeLine:eq(0)');
    clearDom($domJH);
    setDomJH(ProNodePlan,$JQuery,$domJH);
    var $domSJ = $JQuery('.timeLine:eq(1)');
    clearDom($domSJ);
    setDomSJ(ProNodeActual,$JQuery,$domSJ);
}


function initDomConn(dataSource,$JQuery,mileid) {
    var ProNodePlan = dataSource.MinorPlan,
        ProNodeActual = dataSource.MinorActual,
        conLabel = dataSource.conLabel;
    var $domJHConn = $JQuery('.timeLine:eq(2)');
    clearDom($domJHConn);
    setDomJHConn(ProNodePlan,$JQuery,$domJHConn);
    var $domSJConn = $JQuery('.timeLine:eq(3)');
    clearDom($domSJConn);
    setDomSJConn(ProNodeActual,$JQuery,$domSJConn,ProNodePlan.length,mileid);
}

function setDomJH(arr,$JQuery,dom) {
    
    for (let i = 0; i < arr.length; i++){
		
        var str;
		str = '<div class="itemActiveBg">\n' +
				'<div class="yueBox">'+arr[i].month+'月</div>\n' +
				'<div class="dot" data-id="'+arr[i].conid+'"  data-mileid ="'+arr[i].mileid+'"></div>\n' +
				'<div class="sbcgBox" >'+arr[i].miletitle+'</div>\n' +
				'<div class="item"></div>\n' +
				'<div class="boxItem">\n' +
					'<div  class="triangleTopright"></div>\n' +
					'<div class="titleBox">'+arr[i].miledate+'&nbsp;&nbsp;'+arr[i].milecontent+'</div>\n' +
				'</div>\n' +
			'</div>';
		
        dom.append(str);
    }
}


function setDomSJ(arr,$JQuery,dom) {
	 
    var length = arr.length;
    for (let i = 0; i < arr.length; i++){
		
        var lagDay = arr[i].lagDay;
        var colorClass;
        var dotRedClass;
        if(lagDay){
            if(lagDay.indexOf("-") == -1){
                dotRedClass = "";
                lagDay = '（提前'+lagDay+'天)';
                colorClass = 'greenColor';
            }else {
                dotRedClass = "dotRed";
                lagDay = lagDay.replace("-","");
                lagDay = '（滞后'+lagDay+'天)';
                colorClass = 'redColor';
            }
        }
		
		 getTime(arr[i].completedate);
		var str;
		
		if(arr[i].relation>0){
			 str = '<div class="itemActiveBg">\n' +
			         // '<div class="yueBox">'+arr[i].month+'月</div>\n' +
					 '<div class="dotClassBox '+dotRedClass+'"  data-id="'+arr[i].conid+'"  data-mileid ="'+arr[i].mileid+'"></div>\n' +
					 // '<div class="sbcgBox">\n' +
					 // '<div >'+arr[i].miletitle+'</div>\n' +
					 // '<div class="'+colorClass+'">'+lagDay+'</div>\n' +
					 // '</div>\n' +
					 '<div class="itemBox"></div>\n' +
					 '<div class="boxItem">\n' +
					 '<div  class="triangleTopright topBar"></div>\n' +
					 '<div class="titleBox">'+arr[i].completedate+'&nbsp;&nbsp;'+arr[i].milecontent+'</div>\n' +
					 '</div>\n' +
				   '</div>'; 
		}else{
			str = '<div class="itemActiveBg">\n' +
			        '<div class="yueBox">'+arr[i].month+'月</div>\n' +
			        '<div class="dot '+dotRedClass+'"  data-id="'+arr[i].conid+'"  data-mileid ="'+arr[i].mileid+'"></div>\n' +
			        '<div class="sbcgBox">\n' +
			        '<div >'+arr[i].miletitle+'</div>\n' +
			        '<div class="'+colorClass+'">'+lagDay+'</div>\n' +
			        '</div>\n' +
			        '<div class="item"></div>\n' +
			        '<div class="boxItem">\n' +
			        '<div  class="triangleTopright"></div>\n' +
			        '<div class="titleBox">'+arr[i].completedate+'&nbsp;&nbsp;'+arr[i].milecontent+'</div>\n' +
			        '</div>\n' +
			        '</div>';
		}
        dom.append(str);
    }
}

function clearDom(dom) {
    dom.empty();
}


function setDomJHConn(arr,$JQuery,dom) {
	
    var length = arr.length;
    for (let i = 0; i < length; i++){
        var str;
	
		str = '<div class="itemActiveBg">\n' +
				'<div class="yueBox">'+arr[i].month+'月</div>\n' +
				'<div class="dot" data-id="'+arr[i].conid+'"  data-mileid ="'+arr[i].mileid+'"></div>\n' +
				'<div class="sbcgBox" >'+arr[i].miletitle+'</div>\n' +
				'<div class="item"></div>\n' +
				'<div class="boxItem">\n' +
					'<div  class="triangleTopright"></div>\n' +
					'<div class="titleBox">'+arr[i].miledate+'&nbsp;&nbsp;'+arr[i].milecontent+'</div>\n' +
				'</div>\n' +
			'</div>';
		
        dom.append(str);
    }
}

//设置 合同实际 节点
function setDomSJConn(arr,$JQuery,dom,JHLength,mileid) {
	var  mileid = mileid?mileid:"";
    var length = arr.length;
    for (let i = 0; i <arr.length; i++){
        var lagDay = arr[i].lagDay;
        var colorClass;
        var dotRedClass;
        if(lagDay){
            if(lagDay.indexOf("-") == -1){
                dotRedClass = "";
                lagDay = '（提前'+lagDay+'天)';
                colorClass = 'greenColor';
            }else {
                dotRedClass = "dotRed";
                lagDay = lagDay.replace("-","");
                lagDay = '（滞后'+lagDay+'天)';
                colorClass = 'redColor';
            }
        }
        var str;

       
		  if(arr[i].mileid == mileid){
					 
			str = '<div class="itemActiveBg">\n' +
					'<div class="yueBox">'+arr[i].month+'月</div>\n' +
					'<div class="dot dotYellow"  data-id="'+arr[i].conid+'"  data-mileid ="'+arr[i].mileid+'"></div>\n' +
					'<div class="sbcgBox">\n' +
					'<div >'+arr[i].miletitle+'</div>\n' +
					'<div class="'+colorClass+'">'+lagDay+'</div>\n' +
					'</div>\n' +
					'<div class="item"></div>\n' +
					'<div class="boxItem">\n' +
						'<div  class="triangleTopright"></div>\n' +
						'<div class="titleBox">'+arr[i].completedate+'&nbsp;&nbsp;'+arr[i].milecontent+'</div>\n' +
					'</div>\n' +
				'</div>'; 
			  
		  }else{
			  str = '<div class="itemActiveBg">\n' +
			  		'<div class="yueBox">'+arr[i].month+'月</div>\n' +
			  		'<div class="dot '+dotRedClass+'"  data-id="'+arr[i].conid+'"  data-mileid ="'+arr[i].mileid+'"></div>\n' +
			  		'<div class="sbcgBox">\n' +
			  		'<div >'+arr[i].miletitle+'</div>\n' +
			  		'<div class="'+colorClass+'">'+lagDay+'</div>\n' +
			  		'</div>\n' +
			  		'<div class="item"></div>\n' +
			  		'<div class="boxItem">\n' +
			  			'<div  class="triangleTopright"></div>\n' +
			  			'<div class="titleBox">'+arr[i].completedate+'&nbsp;&nbsp;'+arr[i].milecontent+'</div>\n' +
			  		'</div>\n' +
			  	'</div>';
		  }
			
        dom.append(str);
    }
}


//初始  合同下拉框
function setHTOption(form,dataSource) {
    var conLabel = dataSource.conLabel;
    var select = document.getElementById("htOption");
    if (conLabel != null || conLabel.size() > 0) {
        for (var c in conLabel) {
            var option = document.createElement("option");
            option.setAttribute("value", conLabel[c].value);
            option.innerText = conLabel[c].label;
            select.appendChild(option)
        }
    };
    form.render('select');
}


function selectOnMonitor($,form,proId,NYRArr) {
    form.on("select", function(data){
        var connId = data.value
        var dataParams = {
            "proId":proId,
            "year":NYRArr[0],
            "month":NYRArr[1],
            "conIdList":[connId],
			"statu":1
        };
        var dataSource = httpRequestConn($,dataParams);
        initDomConn(dataSource,$);
    });
}


function  getTime(strtime){
	var arr = []; 
	var date = new Date(strtime);
	var time = date.getTime();
    
	console.log(time)
}

